package com.learn.chain.second.interceptors;

import android.text.TextUtils;

import com.learn.chain.second.Interceptor;
import com.learn.chain.second.Request;
import com.learn.chain.second.Response;

public class CallServerInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) {
        Request request = chain.request();
        System.out.println("CallServerInterceptor: " + request.toString());
        // 如果请求头，请求类型，请求体都不为空，则发起网络请求，返回结果
        if (!TextUtils.isEmpty(request.getHeader()) && !TextUtils.isEmpty(request.getMediaType())
                && !TextUtils.isEmpty(request.getBody())) {
            // 发起网络请求，返回结果
            Response response = new Response();
            response.setCallServerInterceptor("CallServerInterceptor");
            return response;
        }
        return null;
    }
}
